package com.atxwq.shop.product.controller;

import com.atxwq.shop.model.dto.product.ProductSkuDto;
import com.atxwq.shop.model.entity.product.ProductSku;
import com.atxwq.shop.model.vo.common.Result;
import com.atxwq.shop.model.vo.common.ResultCodeEnum;
import com.atxwq.shop.model.vo.h5.ProductItemVo;
import com.atxwq.shop.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 前台商品类
 * @Date 2025/5/20 22:19
 * @Created by 12336
 */

@RestController
@RequestMapping("/api/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * @Description 分页查询商品
     * @Date 2025/5/20 22:20
     * @Created by 12336
     */
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<ProductSku>> findByPage(@PathVariable Integer page,
                                                   @PathVariable Integer limit,
                                                   ProductSkuDto productSkuDto){
       PageInfo<ProductSku> productSkuList =  productService.findByPage(page,limit,productSkuDto);
       return Result.build(productSkuList, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/item/{skuId}")
    public Result<ProductItemVo> item(@PathVariable Long skuId){
       ProductItemVo productItemVo =  productService.item(skuId);
       return Result.build(productItemVo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 远程调用
     * @param skuId
     * @return
     */
    @GetMapping("getBySkuId/{skuId}")
    public ProductSku getBySkuId(@Parameter(name = "skuId", description = "商品skuId", required = true) @PathVariable("skuId") Long skuId) {
        ProductSku productSku = productService.getBySkuId(skuId);
        return productSku;
    }


}
